<template>
  <div class="personal">
    <router-link to="/edit_profile">
      <div class="profile">
        <img :src="userInfo.head_img" alt />
        <div class="profile-center">
          <div class="name">
            <span
              class="iconfont"
              :class="{
                iconxingbienan: userInfo.gender == 1,
                iconxingbienv: userInfo.gender == 0,
              }"
            ></span
            >{{ userInfo.nickname }}
          </div>
          <div class="time">{{ newTime | printfTime }}</div>
        </div>
        <span class="iconfont iconjiantou1"></span>
      </div>
    </router-link>
    <van-cell
      title="我的关注"
      is-link
      value="关注的用户"
      @click="attentionFn"
    />
    <van-cell title="我的跟帖" is-link value="跟帖/回复" />
    <van-cell @click="favoriteFn" title="我的收藏" is-link value="文章/视频" />
    <van-cell title="设置" is-link value="" />
    <van-button round type="info" size="normal" color="#eb6112" @click="logout"
      >退出</van-button
    >
  </div>
</template>

<script>
import { getUserInfo } from "@/apis/get";
export default {
  data() {
    return {
      userInfo: {},
      newTime: new Date(),
    };
  },
  created() {
    let id = localStorage.getItem("id");
    getUserInfo(id).then((res) => {
      // console.log(res);
      this.userInfo = res.data.data;
    });
  },
  methods: {
    // 退出登录
    logout() {
      localStorage.removeItem("token");
      localStorage.removeItem("id");
      this.$router.push({
        path: "login",
      });
    },
    // 跳转关注
    attentionFn() {
      this.$router.push({
        path: "attention",
      });
    },
    // 跳转文章收藏
    favoriteFn() {
      this.$router.push({
        path: "favorite",
      });
    },
  },
};
</script>

<style lang="less" scoped>
.personal {
  width: 100vw;
  height: 100vh;
  background-color: #eee;
}
a {
  color: #666;
}
.profile {
  display: flex;
  padding: 20px 10px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 5px #ddd solid;

  img {
    width: (70 / 360) * 100vw;
    height: (70 / 360) * 100vw;
    border-radius: 50%;
  }

  .profile-center {
    flex: 1;
    padding: 0 10px;
  }

  .name {
    span {
      color: #75b9eb;
    }
  }

  .time {
    color: #666;
    font-size: 14px;
    margin-top: 5px;
  }
}
.van-cell {
  border-bottom: 1px solid #ddd;
  background-color: #eee;
}
.van-button {
  display: block;
  margin: 15px auto;
  width: 95%;
}
</style>